﻿using SdmxMl.Manager;

namespace SdmxMl.Multiplexor
{
    /// <summary> Multiplexor Factory (Singleton) </summary>
    public class Mux
    {
        /// <summary> The multiplexor instancemanaging all registries proxy  </summary>
        public static IRegistry Instance;

        #region Constructors

        static Mux()
        {
            Instance = new RegistryMultiplex();
        }

        private Mux()
        {
        }
        #endregion

        #region instance creation Methods

        /// <summary> Creates new multiplexor instance</summary>
        /// <param name="url">Url of main registry</param>
        public static void CreateNewInstance(string url)
        {
            Instance = new RegistryMultiplex(url);
        }

        /// <summary> Creates new instance of multiplexor using config Url</summary>
        public static void CreateNewInstance()
        {
            Instance = new RegistryMultiplex();
        }

        #endregion

        #region Helper for New SMS Registry

        public static bool IsNewSmsRegistry
        {
            get
            {
                return Instance != null && Instance.IsNewSmsRegistry == true;
            }
        }
        public static string FullIdSmsAdapter(string fullId)
        {
            if (SdmxMl.Multiplexor.Mux.IsNewSmsRegistry)
            {
                if (fullId.StartsWith("CH1_"))
                {
                    SdmxMl.Common.ArtefactRefBase arb = new SdmxMl.Common.ArtefactRefBase(fullId);
                    arb.AgencyId = "CH1";
                    fullId = arb.FullIdent;
                }
            }
            return fullId;
        }

        #endregion
    }
}
